package accessory;

import graph.GraphRendererFrame;

import java.util.HashMap;

import console.view.ConsoleContainer;
import console.view.ConsoleFrame;

public class CLog {
	
	private static HashMap<String, GraphRendererFrame> graphRenderer = new HashMap<String, GraphRendererFrame>();
	private static ConsoleContainer consoleContainer;
	
	public CLog(){
		
	}

	public static void info(String text){
		System.out.println(printAction(text));
	}
	
	public static void error(String text){
		System.err.println(printAction(text));
	}

	public static void error(Exception e){
		e.printStackTrace();
	}
	
	public static void renderGraph(String frame, int val){
		if(graphRenderer.get(frame) == null){
			GraphRendererFrame renderer = new GraphRendererFrame(frame);
			renderer.renderValue(40);
			renderer.renderValue(val);
			graphRenderer.put(frame, renderer);
		}
		else {
			graphRenderer.get(frame).renderValue(val);
		}
	}

	public static void setConsoleContainer(ConsoleContainer console) {
		consoleContainer = console; 
	}
	
	private static String printAction(String text){
		if(consoleContainer != null){
			consoleContainer.printText(text);
		}
		return text;
	}
}